package com.itheima.search.mq;

import com.itheima.search.constants.MqConstants;
import com.itheima.search.service.SearchService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class HotelListener {

    @Autowired
    private SearchService iSearchService;


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MqConstants.ITEM_INSERT_QUEUE),
            exchange = @Exchange(name = MqConstants.ITEM_EXCHANGE,type = ExchangeTypes.TOPIC),
            key = MqConstants.ITEM_INSERT_KEY
    ))
    public void listenHotelInsertOrUpdate(Long id){
        iSearchService.insertById(id);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MqConstants.ITEM_DELETE_QUEUE),
            exchange = @Exchange(name = MqConstants.ITEM_EXCHANGE,type = ExchangeTypes.TOPIC),
            key = MqConstants.ITEM_DELETE_KEY
    ))
    public void listenHotelDelete(Long id){
        iSearchService.deleteById(id);
    }
}